﻿using System;
using System.Collections.Generic;
using UnityEngine;

public static class EntityValueChecker
{
    const float EPS = 1e-4F;

    static Dictionary<Type, Func<object, object, bool>> checkFuncDic = new Dictionary<Type, Func<object, object, bool>>
    {

        {
            typeof(float),
            (object a,object b) =>
            {
                return Mathf.Abs((float)a-(float)b)<EPS;
            }
        },
        {
            typeof(Vector3),
            (object a,object b) =>
            {
                Vector3 aa=(Vector3)a;
                Vector3 bb=(Vector3)b;
                return CheckValueEqual(typeof(float),aa.x,bb.x)&&CheckValueEqual(typeof(float),aa.y,bb.y)&&CheckValueEqual(typeof(float),aa.z,bb.z);
            }
        }
    };

    public static bool CheckValueEqual(Type type,object a, object b) 
    {
        if (checkFuncDic.ContainsKey(type))
        {
            return checkFuncDic[type](a, b);
        }
        else
        {
            return a.Equals(b);
        }
    }
    public static bool CheckValueEqual<T>(T a,T b)
    {
        if (checkFuncDic.ContainsKey(typeof(T)))
        {
            return checkFuncDic[typeof(T)](a, b);
        }else
        {
            return a.Equals(b);
        }
    }
}